package com.ngd.slidepannel.card;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ngd.slidepannel.R;


/**
 * 卡片View项
 *
 * @author xmuSistone
 */
@SuppressLint("NewApi")
public class CardItemView extends LinearLayout {

    private ImageView card_image_view;
    private ImageView ivUnlike;
    private ImageView ivLike;
    private ImageView ivWechat;
    private ImageView ivMessage;
    private ImageView iv_VIP;
    private TextView tv_coverNumber;
    private TextView tvUserName;
    private TextView tvAge;
    private TextView tvConstellation;
    private TextView tvVIP;
    private TextView tvOther;
    private Context context;
    private CardItemClickListener listener;

    static String UNLIKE_TYPE = "unlike";
    static String LIKE_TYPE = "like";
    static String WECHAT_TYPE = "wechat";
    static String Message_TYPE = "message";

    public CardItemView(Context context) {
        this(context, null);
        this.context = context;
        init();
    }

    public CardItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        this.context = context;
        init();
    }

    public CardItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        init();
    }

    public CardItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.context = context;
        init();
    }


    void init() {
        System.out.println("没有进入这个页面吗");
        View inflate = inflate(context, R.layout.card_item, this);
        ivUnlike = (ImageView) findViewById(R.id.iv_unlike);
        ivLike = (ImageView) findViewById(R.id.iv_like);
        ivWechat = (ImageView) findViewById(R.id.iv_wechat);
        ivMessage = (ImageView) findViewById(R.id.iv_message);


        iv_VIP = (ImageView) findViewById(R.id.iv_VIP);
        card_image_view = (ImageView) findViewById(R.id.iv_Cover);
        tv_coverNumber = (TextView) findViewById(R.id.tv_coverNumber);
        tvUserName = (TextView) findViewById(R.id.tv_user_name);
        tvAge = (TextView) findViewById(R.id.tv_sex_age);
        tvConstellation = (TextView) findViewById(R.id.tv_constellation);
        tvOther = (TextView) findViewById(R.id.tv_other);
    }

    @SuppressLint("SetTextI18n")
    public void fillData(CardDataItem itemData) {
        Glide.with(context).load(itemData.getImagePath()).into(card_image_view);

        tvUserName.setText(itemData.userName);
//        tvAge.setText(itemData.getAge());
//        tvConstellation.setText(itemData.getConstellation());
//        tv_coverNumber.setText(itemData.getCover_number() + "");
//        tvOther.setText(itemData.getCity_name() + "  " + itemData.getDistance() + "km");
//
//        if (itemData.getLevel().equals("0")) {
//            tvVIP.setVisibility(View.GONE);
//            iv_VIP.setVisibility(View.GONE);
//        } else {
//            tvVIP.setVisibility(View.VISIBLE);
//            iv_VIP.setVisibility(View.VISIBLE);
//        }
//
        Drawable drawableLeft;
        if (true) {
            drawableLeft = getResources().getDrawable(R.drawable.ic_female);
        } else {
//            drawableLeft = getResources().getDrawable(R.drawable.ic_male);
        }
        tvAge.setCompoundDrawablePadding(4);
        tvAge.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,
                null, null, null);
    }

    void onclickButtonChangeListner(CardItemClickListener listener) {
        this.listener = listener;
    }


//    @Override
//    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        getParent().requestDisallowInterceptTouchEvent(true);
//        System.out.println("onInterceptTouchEvent  child   " + super.onInterceptTouchEvent(ev));
//        return super.onInterceptTouchEvent(ev);
//    }

    /**
     * 卡片按钮点击事件
     */
    public interface CardItemClickListener {
        void clickItem(View view);
    }


}
